#============================================================
#	Hud
#============================================================
# @datetime: 2022-4-21 01:57:10
#============================================================
extends CanvasLayer


enum TabIndex {
	PlayerInfo,
	ItemPanel,
	ItemData,
}


onready var _tab_container := get_node("TabContainer") as TabContainer
onready var _player_info := get_node("TabContainer/PlayerInfo") as HUD_PlayerInfo
onready var _item_panel := get_node("TabContainer/ItemPanel") as HUD_ItemPanel
onready var _item_data := get_node("TabContainer/ItemData") as HUD_ItemData
onready var _item_info := get_node("ItemInfo")


#============================================================
#   Set/Get
#============================================================
func get_node_index(node_name: String) -> int:
	return get_node("TabContainer/" + node_name).get_index()


#============================================================
#   内置
#============================================================
func _ready():
	_item_info.rect_min_size = _item_info.rect_size
	_item_info.set_margins_preset(Control.PRESET_TOP_WIDE)


func _unhandled_key_input(event: InputEventKey):
	if event.pressed:
		match event.scancode:
			KEY_F2:
				change_panel(TabIndex.PlayerInfo if _tab_container.current_tab == TabIndex.ItemData else TabIndex.ItemData)


#============================================================
#   自定义
#============================================================
func change_panel(index: int):
	_tab_container.current_tab = index


#============================================================
#   连接信号
#============================================================
func _on_PlayerInfo_show_item():
	change_panel(TabIndex.ItemPanel)


func _on_TabContainer_tab_changed(tab):
	get_tree().paused = not (tab in [
		TabIndex.PlayerInfo
	])


func _on_ItemData_select_item(data: Dictionary):
	Logger.info(self, ["添加一个物品：", data])
	WrapperHelper.get_item(Global.player).add(data)

